<?php // $Id: vw_idx_check.php,v 1.8.8.1 2007/01/31 09:36:52 ajdonnison Exp $

global $cfgDir, $cfgFile, $failedImg, $filesDir, $locEnDir, $okImg, $tblwidth, $tmpDir;

$cfgDir = isset($cfgDir) ? $cfgDir : DP_BASE_DIR."/includes";
$cfgFile = isset($cfgFile) ? $cfgFile : DP_BASE_DIR."/includes/config.php";
$filesDir = isset($filesDir) ? $filesDir : DP_BASE_DIR."/files";
$locEnDir = isset($locEnDir) ? $locEnDir : DP_BASE_DIR."/locales/en";
$tmpDir = isset($tmpDir) ? $tmpDir : DP_BASE_DIR."/files/temp";
$tblwidth = isset($tblwidth) ? $tblwidth :'100%';
$chmod = 0777;

function dPgetIniSize($val) {
	$val = trim($val);
	if (strlen($val <= 1)) return $val;
	$last = $val{strlen($val)-1};
	switch($last) {
	case 'k':
	case 'K':
		return (int) $val * 1024;
		break;
	case 'm':
	case 'M':
		return (int) $val * 1048576;
		break;
	default:
		return $val;
	}
}

?>

<table cellspacing="0" cellpadding="0" border="0" width="<?php echo $tblwidth; ?>" align="center">
<tr>
	<td align="center">
	<table cellpadding="4" cellspacing="0" width="100%" class="list">
	<tr>
		<td colspan="3"><b>Check for Requirements</b></td>
	</tr>
	<tr class="second">
		<td class="item" width="220px"><li>PHP Version &gt;= 4.1</li></td>
	<? if (version_compare(phpversion(), '4.1', '<')) { ?>
		<td align="left" width="16px"><?=$failedImg?></td>
		<td><b class="error">(<?=phpversion()?>): dotProject may not work. Please upgrade!</b></td>
	<? } else { ?>
		<td align="left" width="16px"><?=$okImg?></td>
		<td><b class="message"><span class="item"> (<?=phpversion()?>)</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>Server API</li></td>
	<? if (php_sapi_name() != "cgi") { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item">(<?=php_sapi_name()?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error">CGI mode is likely to have problems</b></td>
	<? } ?>
		</td>
	</tr>

	<tr class="second">
		<td class="item"><li>GD Support (for GANTT Charts)</li></td>
	<? if (extension_loaded('gd')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message">&nbsp;</b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error">GANTT Chart functionality may not work correctly</b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>Zlib compression Support</li></td>
	<? if (extension_loaded('zlib')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message">&nbsp;</b></td>
	<? } else { ?>
		<td><?=$failedImg?></td>
		<td><b class="error">Some non-core modules such as Backup may have restricted operation</b></td>
	<? } ?>
	</tr>
	<?php
		$maxfileuploadsize = min(dPgetIniSize(ini_get('upload_max_filesize')), dPgetIniSize(ini_get('post_max_size')));
		$memory_limit = dPgetIniSize(ini_get('memory_limit'));
		if ($memory_limit > 0 && $memory_limit < $maxfileuploadsize) $maxfileuploadsize = $memory_limit;
		// Convert back to human readable numbers
		if ($maxfileuploadsize > 1048576)
			$maxfileuploadsize = (int)($maxfileuploadsize / 1048576) . 'M';
		else if ($maxfileuploadsize > 1024)
			$maxfileuploadsize = (int)($maxfileuploadsize / 1024) . 'K';
	?>
	<tr class="second">
		<td class="item"><li>File Uploads</li></td>
	<? if (ini_get('file_uploads')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item">(Max File Upload Size: <?=$maxfileuploadsize?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> Upload functionality will not be available</span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>Session Save Path writable?</li></td>
	<?php 
		$sspath = ini_get('session.save_path');
		if (! $sspath) {
	?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error">Fatal:</b> <span class="item">session.save_path</span> <b class='error'> is not set</b></td>
	<? } else if (is_dir($sspath) && is_writable($sspath)) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item">(<?=$sspath?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error">Fatal: <span class="item"><?=$sspath?></span> not existing or not writable</b></td>
	<? } ?>
	</tr>
	</table>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td align="center">
	<table cellpadding="4" cellspacing="0" width="100%" class="list">
	<tr>
		<td class="title" colspan="3"><b>Database Connectors</b></td>
	</tr>
	<tr>
		<td class="help" colspan="3"><p>The next tests check for database support compiled with php. We use the ADODB database abstraction layer which comes with drivers for many databases. Consult the ADODB documentation for details. <p>For the moment only MySQL is fully supported, so you need to make sure it is available.</td>
	</tr>
	<tr class="second">
		<td class="item" width="220px"><li>iBase Support</li></td>
	<? if (function_exists( 'ibase_connect' ) && function_exists( 'ibase_server_info' )) { ?>
		<td align="left" width="16px"><?=$okImg?></td>
		<td><b class="message"><span class="item">(<?=ibase_server_info()?>)</span></b></td>
	<? } else { ?>
		<td align="left" width="16px"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>Informix Support</li></td>
	<? if (function_exists( 'ifx_connect' )) { ?>
		<td align="left"><b class="message"><?=$okImg?></b></td>
		<td>&nbsp;</td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>LDAP Support</li></td>
	<? if (function_exists( 'ldap_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"> </span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>mSQL Support</li></td>
	<? if (function_exists( 'msql_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"></span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>MSSQL Server Support</li></td>
	<? if (function_exists( 'mssql_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"></span></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>MySQL Support</li></td>
	<? if (function_exists( 'mysql_connect' )) { ?>
	<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item">(<?=@mysql_get_server_info()?>)</span></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>ODBC Support</li></td>
	<? if (function_exists( 'odbc_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"></span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>Oracle Support</li></td>
	<? if (function_exists( 'oci_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"> (<?=ociserverversion()?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>PostgreSQL Support</li></td>
	<? if (function_exists( 'pg_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"></span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>SQLite Support</li></td>
	<? if (function_exists( 'sqlite_open' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item">(<?=sqlite_libversion()?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item"><li>Sybase Support</li></td>
	<? if (function_exists( 'sybase_connect' )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"> </span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><span class="warning">Not available</span></td>
	<? } ?>
	</tr>
	</table>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td align="center">
	<table cellpadding="4" cellspacing="0" width="100%" class="list">
	<tr>
		<td class="title" colspan="3"><b>Check for Directory and File Permissions</b></td>
	</tr>
	<tr>
		<td class="help" colspan="3">If the message 'World Writable' appears after a file/directory, then Permissions for this File have been set to allow all users to write to this file/directory. Consider changing this to a more restrictive setting to improve security. You will need to do this manually.
		</td>
	</tr>
	<?php
		$okMessage="";
		if ((file_exists( $cfgFile ) && !is_writable( $cfgFile )) ||
			(!file_exists( $cfgFile ) && !(is_writable( $cfgDir )))) {
	
			@chmod( $cfgFile, $chmod );
			@chmod( $cfgDir, $chmod );
			$filemode = @fileperms($cfgFile);
			if ($filemode & 2) $okMessage="<span class='error'> World Writable</span>";
		}
	?>
	<tr class="second">
		<td class="item" width="220px">./includes/config.php writable?</td>
	<? if ( is_writable( $cfgFile ) || is_writable( $cfgDir )) { ?>
		<td align="left" width="16px"><?=$okImg?></td>
		<td><b class="message"><?=$okMessage?></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning">Configuration process can still be continued. Configuration file will be displayed at the end, just copy & paste this and upload.</span></b></td>
	<? } ?>
	</tr>
	<?php
		$okMessage="";
		if (!is_writable( $filesDir )) @chmod( $filesDir, $chmod );

		$filemode = @fileperms($filesDir);
		if ($filemode & 2) $okMessage="<span class='error'> World Writable</span>";
	?>
	<tr class="second">
		<td class="item">./files writable?</td>
	<? if (is_writable( $filesDir )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><?=$okMessage?></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> File upload functionality will be disabled</span></b></td>
	<? } ?>
	</tr>
	<?php
		$okMessage="";
		if (!is_writable( $tmpDir ))
			@chmod( $tmpDir, $chmod );

		$filemode = @fileperms($tmpDir);
		if ($filemode & 2)
			$okMessage="<span class='error'> World Writable</span>";
	?>
	<tr class="second">
		<td class="item">./files/temp writable?</td>
	<? if (is_writable( $tmpDir )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><?=$okMessage?></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> PDF report generation will be disabled</span></b></td>
	<? } ?>
	</tr>
	<?php
		$okMessage="";
		if (!is_writable( $locEnDir ))
			@chmod( $locEnDir, $chmod );

		$filemode = @fileperms($locEnDir);
		if ($filemode & 2)
			$okMessage="<span class='error'> World Writable</span>";
	?>
	<tr class="second">
		<td class="item">./locales/en writable?</td>
	<? if (is_writable( $locEnDir )) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><?=$okMessage?></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> Translation files cannot be saved. Check /locales and subdirectories for permissions.</span></b></td>
	<? } ?>
	</tr>
	</table>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td align="center">
	<table cellpadding="4" cellspacing="0" width="100%" class="list">
	<tr>
		<td class="title" colspan="3"><b>Recommended PHP Settings</b></td>
	</tr>
	<tr class="second">
		<td class="item" width="220px">Safe Mode = OFF?</td>
	<? if (!ini_get('safe_mode')) { ?>
		<td align="left" width="16px"><?=$okImg?></td>
		<td><b class="message"></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"></span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item">Register Globals = OFF?</td>
	<? if (!ini_get('register_globals')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> There are security risks with this turned ON</span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item">Session AutoStart = ON?</td>
	<? if (ini_get('session.auto_start')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> Try setting to ON if you are experiencing a WhiteScreenOfDeath</span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item">Session Use Cookies = ON?</td>
	<? if (ini_get('session.use_cookies')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> Try setting to ON if you are experiencing problems logging in</span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item">Session Use Trans Sid = OFF?</td>
	<? if (!ini_get('session.use_only_cookies') && !ini_get('session.use_trans_sid')) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning"> There are security risks with this turned ON</span></b></td>
	<? } ?>
	</tr>
	</table>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td align="center">
	<table cellpadding="4" cellspacing="0" width="100%" class="list">
	<tr>
		<td class="title" colspan="3"><b>Other Recommendations</b></td>
	</tr>
	<tr>
		<td class="help" colspan="3">
			<p>The dotProject team openly recommend Free Open Source software (FOSS).  This is not just
				because dotProject is a FOSS application, but because we believe that the FOSS development
				method results in better software, with a lower Total Cost of Ownership (TCO).
			<p>These recommendations reflect that belief, and the fact that as FOSS developers, we
				develop on FOSS systems, so they will have better support sooner than other non-FOSS
				systems.
		</td>
	</tr>
	<tr class="second">
		<td class="item" width="220px">Free Operating System?</td>
	<? if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { ?>
		<td align="left" width="16px"><?=$okImg?></td>
		<td><b class="message"><span class="item"> (<?=php_uname()?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning">It seems you are using a proprietary operating system.  You might want to consider a Free Open Source operating system such as Linux.  dotProject is usually tested on Linux first and will always have better support for Linux than other operating systems.</span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item">Supported Web Server?</td>
	<? if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') != false) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"> (<?=$_SERVER['SERVER_SOFTWARE']?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning">It seems you are using an unsupported web server.  Only Apache Web server is fully supported by dotProject, and using other web servers may result in unexpected problems.</span></b></td>
	<? } ?>
	</tr>
	<tr class="second">
		<td class="item">Standards Compliant Browser?</td>
	<? if (stristr($_SERVER['HTTP_USER_AGENT'], 'msie') == false) { ?>
		<td align="left"><?=$okImg?></td>
		<td><b class="message"><span class="item"> (<?=$_SERVER['HTTP_USER_AGENT']?>)</span></b></td>
	<? } else { ?>
		<td align="left"><?=$failedImg?></td>
		<td><b class="error"><span class="warning">It seems you are using Internet Explorer.  This browser has many known security risks and is not standards compliant.  Consider using a browser such as Firefox - the dotProject team in the main develops for Firefox first.</span></b></td>
	<? } ?>
	</tr>
	</table>
	</td>
</tr>
</table>
